<?php
 class CommentAction extends Action{
 	public function index(){
 		$db=M();
 		Import('ORG.Util.Page');
 		$sql1="select count(*) tot from comment,user,shop where comment.user_id=user.id and comment.shop_id=shop.id";
 		$tot=$db->query($sql1);
 		$count=$tot[0]['tot'];
 		$page=new Page($count,10);
 		$show=$page->show();
 		$sql2="select c.*,u.username,s.name from comment c ,user u,shop s
 						where c.user_id=u.id and c.shop_id=s.id
 						limit {$page->firstRow},{$page->listRows}
 						";

 		$rows=$db->query($sql2);
 		$this->assign('show',$show);
 		$this->assign('rows',$rows);
 		$this->display();
 	}
 	// 添加模版
 	public function add(){
 		$this->display();
 	}
 	// 添加操作
 	public function add_handle(){
 		$Comment=M('Comment');
 		$_POST['password']=md5($_POST['password']);
 		if($Comment->create()){
 			$Comment->add();
 			$this->redirect('index');
 		}else{
 			$this->error('添加失败');
 		};
 	}

 	// 删除
 	// 删除
 	public function delete(){
 		$Comment=M('Comment');
 		// 获取$.get传过来的id
 		$id=$_GET['id'];
		$re=$Comment->delete($id);
		if($re){
			$arr['status']=1;
			$arr['info']='删除成功';
			echo json_encode($arr);
		}
 		
 		
 	}

 	// 修改模版
 	public function edit(){
 		$Comment=M('Comment');
 		$id=$_GET['id'];
 		$row=$Comment->find($id);
 		$this->assign('row',$row);
 		$this->display();
 	}
 	// 修改操作
 	public function edit_handle(){
 		$Comment=M('Comment');
 		if($Comment->create()){
 			$Comment->save();
 			$this->redirect('index');
 		};
 	}
 }
?>